<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>分配角色</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="分配,角色">
	<meta http-equiv="description" content="This is my page">

	<style type="text/css">
	.roleDivClass
	{
		display:inline;
		float:left;
		width:120;
	}
	
	.hasCheckDiv
	{
		color:red;
	}
	</style>

  </head>
  
  <body>
    <center>
    	<s:form name="frm" id="frm" method="post" action="" namespace="">
    		<s:hidden name="user.id"></s:hidden>
    	
    		<jsp:include page="/jsp/outward/business/common/menuLink.jsp">
    			<jsp:param name="menuLink" value="[{'name':'系统管理'},{'name':'用户管理'},{'name':'分配角色'}]"/>
    			<jsp:param name="width" value="70%"/>
    		</jsp:include>
    		
    		<table width="100%" cellspacing="1" cellpadding="3" bgcolor="#CCCCCC">
    			<tr bgcolor="#FFFFFF">
    				<td width="15%" height="30" align="right" class="label">
    					用户名称：
    				</td>
    				<td width="80%" align="left">
    					<s:property value="user.username"/>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td align="right" class="label">
    					分配角色：
    					<br>
    					全选<input type="checkbox" onclick="cbCheck(this, 'roleIds')" />
    				</td>
    				<td width="80%" align="left">
    					<s:iterator value="roleList" status="s">
    						<div id="roleDiv<s:property value='id' />" class="roleDivClass">
    							<input type="checkbox" name="roleIds" id="role<s:property value='id' />" value="<s:property value='id' />" />
    							<s:property value="roleName"/>
    						</div>
    					</s:iterator>
    				</td>
    			</tr>
    		</table>
    		
    		<table width="100%" cellspacing="0">
    			<tr>
    				<td align="center" valign="bottom" height="30">
    					<input type="button" value="修改" class="btn" onclick="assignRole()" />
    				</td>
    			</tr>
    		</table>
    		
    		
    	</s:form>
    </center>
    
    <script type="text/javascript">
    $(function(){
    	var roleIds = [<s:property value='userRoleIds' />];
    	var len = roleIds.length;
    	for(var i = 0; i < len; i++)
    	{
    		var rolex = $('#role' + roleIds[i]);
    		var roleDivx = $('#roleDiv' + roleIds[i]);
    		roleDivx.addClass('hasCheckDiv');
    		rolex.attr('checked', true);
    	}
    });
    
    function assignRole()
    {
    	$.ajax({
    		url:'${CONTEXT_PATH}/inner/user/assignRole.action',
    		type:'post',
    		data:$("#frm").serialize(),
    		success:
    			function(result){
    				showMsg('修改成功。', function(){
			    		window.close();
			    	});
    			}
    	});
    }
    </script>
  </body>
</html>
